package ex_from_web;

	import java.util.Arrays;
	/**
	 * 
	 * Sorting an Array using Comparable interface example
	 */
	class Item implements Comparable<Item>{
	    String name;
	    double price;
	    
	    public Item(String name, double price) {
	        this.name = name;
	        this.price = price;
	    }

	    public String getName() {
	        return name;
	    }

	    public void setName(String name) {
	        this.name = name;
	    }

	    public double getPrice() {
	        return price;
	    }

	    public void setPrice(double price) {
	        this.price = price;
	    }
	    
	    public String toString() {
	        return "[" + name + " - " + price + "]";
	    }
	        //sort by price - ascending
	        @Override
	    public int compareTo(Item i) {
	        return Double.compare(this.getPrice(), i.getPrice());
	    }
	}
	public class sort_array {
	     
	   public static void main(String[] args) {
	     Item[] items = new Item[3];
	     
	     items[0] = new Item("Milk", 0.88);
	     items[1] = new Item("Computer", 245.67);
	     items[2] = new Item("Shoes", 48.42);
	        
	     System.out.println("Ascending price:");
	     Arrays.sort(items);
	     for (Item i : items) {
	    System.out.println(i);
	     }
	  }
	}